Use unlikely() in BUG_ON()/WARN_ON()
authorKeir Fraser <keir.fraser@citrix.com>
Tue, 31 Mar 2009 12:22:12 +0000 (13:22 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Tue, 31 Mar 2009 12:22:12 +0000 (13:22 +0100)
-fno-reorder-blocks was added in c/s 1712, when x86-64 just started to
become enabled. The reason it got added is entirely unclear to me, and
it prevents the intended effect of unlikely() constructs (in
particular
the ones added here) of moving out of line code which is expected to
never get executed, as well as using forward branches (which are
statically predicted taken by various processors' branch prediction
units) preferably to reach infrequently executed code.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
xen/arch/x86/Rules.mk
xen/include/xen/lib.h

index e9e1d5b95255a8629daa06bdc2b59b633981929f..d97cea47778f9f54e38586a82c7cef0a22ab2686 100644 (file)
@@ -42,7 +42,7 @@ x86_64 := n
 endif
 
 ifeq ($(TARGET_SUBARCH),x86_64)
-CFLAGS += -mno-red-zone -fpic -fno-reorder-blocks
+CFLAGS += -mno-red-zone -fpic
 CFLAGS += -fno-asynchronous-unwind-tables
 # -fvisibility=hidden reduces -fpic cost, if it's available
 ifneq ($(call cc-option,$(CC),-fvisibility=hidden,n),n)
index 93fdabb9f117d2736d9ada05c23a5355e2e472bb..f5c21f64f75894953238a377fd509e237a7b62c4 100644 (file)
@@ -12,8 +12,8 @@
 void __bug(char *file, int line) __attribute__((noreturn));
 void __warn(char *file, int line);
 
-#define BUG_ON(p)  do { if (p) BUG();  } while (0)
-#define WARN_ON(p) do { if (p) WARN(); } while (0)
+#define BUG_ON(p)  do { if (unlikely(p)) BUG();  } while (0)
+#define WARN_ON(p) do { if (unlikely(p)) WARN(); } while (0)
 
 /* Force a compilation error if condition is true */
 #define BUILD_BUG_ON(condition) ((void)sizeof(struct { int:-!!(condition); }))